﻿@using Huirui.Cavan.Domain.MainBoundedContext.SystemModule
@model Huirui.Cavan.Presentation.ViewModel.StockModule.IStockInitialBalanceViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.ADD, ControllerConst.STOCKINITIALBALANCE))
{
    <div class="tool_bar">
        <input id="stockinitialbalance_save" type="submit" style="display: none;" />
        <input id="stockinitialbalance_reset" type="reset" style="display: none" />
        <a href="#" id="save_stockinitialbalance" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'" onclick="javascript:$('#stockinitialbalance_save').click()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'" id="stockinitialbalanceReset">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'" onclick="toggleHeard()">折叠/展开</a>
    </div>
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label>仓库:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.WareHouse.Address, new { id = "stockinitialbalance_wareHouseAddress" })
                @Html.HiddenFor(m => m.Item.WareHouse.Id, new { id = "stockinitialbalance_wareHouseId", style = "display:none;" })
            </td>
            <td class="c100">
                <label>余额日期:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.InitialDate, new { id = "stockinitialbalance_initialDate", @class = "Wdate", @onfocus = "WdatePicker({wdate:true,isShowClear:false,readOnly:true,skin:'whyGreen'})" })
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>存货名称:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Stock.Name, new { id = "stockinitialbalance_stockName" })
                @Html.HiddenFor(m => m.Item.Stock.Id, new { id = "stockinitialbalance_stockId" })
            </td>
            <td class="c100">
                <label>数量:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Number, new { id = "stockinitialbalance_number" })
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>单位成本:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.UnitCost, new { id = "stockinitialbalance_unitCost" })
            </td>
            <td class="c100">
                <label>金额:</label>
            </td>
            <td class="c160">
                @Html.TextBox("amount", "", new { id = "stockinitialbalance_amount", disabled = "true" })
            </td>
        </tr>
    </table>
}
<table id="stockinitialbalance_dg">
    <thead>
        <tr>
            <th field="WareHouseAddress" width="80">仓库 </th>
            <th field="InitialDate" width="80">余额日期 </th>
            <th field="StockName" width="80">存货名称 </th>
            <th field="Number" width="80">数量 </th>
            <th field="UnitCost" width="80">单位成本 </th>
            <th field="Amount" width="80">金额 </th>
        </tr>
    </thead>
</table>
<div id="stockinitialbalancetb">
    <a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="javascript:alert('引出')">引出</a>
</div>
@{ Html.RenderAction(ActionConst.SEARCH, ControllerConst.STOCK, new { purpose = "ForInitialBalance" }); }
@{ Html.RenderAction(ActionConst.SEARCH, ControllerConst.WAREHOUSE, new { purpose = "ForInitialBalance" }); }
<script type="text/javascript">
    $(function ()
    {
        $("form[action^='/stockinitialbalance/add']").submit(function ()
        {
            $('a#save_stockinitialbalance').linkbutton('disable');
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data)
                {
                    if (data.IsSuccess)
                    {
                        $('#stockinitialbalance_dg').datagrid('reload');
                    }
                    else
                    {
                        $.messager.alert("提示", data.Messages[0]);
                    }
                    $("#stockinitialbalance_dg").click();
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })
            $('a#save_stockinitialbalance').linkbutton('enable');
            return false;
        });

        $('#stockinitialbalance_dg').datagrid({
            title: "存货初余额列表",
            singleSelect: true,
            idfield: "ID",
            toolbar: '#stockinitialbalancetb',
            url: "/stockinitialbalance/list"
        });

        $("#stockinitialbalanceReset").bind("click", function ()
        {
            $("#stockinitialbalance_stockId").val("");
            $("#stockinitialbalance_wareHouseId").val("");
            $("#currency_reset").click();
        });

        $("#stockinitialbalance_stockName").bind("click", function ()
        {
            InitSelectStock('stocksForInitialBalance');
            openWindow("selectStockWindowForInitialBalance");
        });

        $("#searchStockForInitialBalance").submit(function ()
        {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result)
                {
                    if (result.total > 0)
                    {
                        $('#stocksForInitialBalance').datagrid({
                            data: result,
                            checkOnSelect: true,
                            selectOnCheck: true
                        });
                    }
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#doSelectStockForInitialBalance").bind("click", function ()
        {
            var currentRow = $('#stocksForInitialBalance').datagrid('getSelected');
            $("#stockinitialbalance_stockId").val(currentRow.Id);
            $("#stockinitialbalance_stockName").val(currentRow.Name);
            closeWindow("selectStockWindowForInitialBalance");
        });

        $("#stockinitialbalance_wareHouseAddress").bind("click", function ()
        {
            InitSelectWareHouse('wareHousesForInitialBalance');
            openWindow("selectWareHouseWindowForInitialBalance");
        });

        $("#searchWareHouseForInitialBalance").submit(function ()
        {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result)
                {
                    if (result.total > 0)
                    {
                        $('#wareHousesForInitialBalance').datagrid({
                            data: result,
                            checkOnSelect: true,
                            selectOnCheck: true
                        });
                    }
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#doSelectWareHouseForInitialBalance").bind("click", function ()
        {
            var currentRow = $('#wareHousesForInitialBalance').datagrid('getSelected');
            $("#stockinitialbalance_wareHouseId").val(currentRow.Id);
            $("#stockinitialbalance_wareHouseAddress").val(currentRow.Address);
            closeWindow("selectWareHouseWindowForInitialBalance");
        });

        $("#stockinitialbalance_number").bind("blur", function ()
        {
            caculateAmount();
        });

        $("#stockinitialbalance_unitCost").bind("blur", function ()
        {
            caculateAmount();
        });

        function caculateAmount()
        {
            if (parseFloat($("#stockinitialbalance_unitCost").val()) > 0 && parseFloat($("#stockinitialbalance_number").val()) > 0)
            {
                $("#stockinitialbalance_amount").val(parseFloat($("#stockinitialbalance_unitCost").val()) * parseFloat($("#stockinitialbalance_number").val()));
            }
        }
    });
</script>
